package com.example.allshengmedical.experimentanalyze.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.os.Environment;
import android.text.TextUtils;

import com.example.allshengmedical.R;
import com.example.allshengmedical.R.color;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineDataSet;

//rawdata的数据获取
public class RawDataUtil {
	// 文件信息
	private String folderName;
	private String fileName;
	private Context context;
	private StringBuffer contextString = new StringBuffer();
	private String appFilePath = Environment.getExternalStorageDirectory()
			+ "/" + "AllShengMedical";

	// 曲线图
	// 上半部
	private ArrayList<MethodBean> activityMethodBeans = new ArrayList<MethodBean>();
	// 重复次数
	private int repititions;

	// 基因盘数据
	public ArrayList<LayoutTableBean> activityLayoutTableBeans;

	// 基因盘数据
	public List<HashMap<String, Object>> dataSourceListBlock1 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock2 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlockToShow = new ArrayList<HashMap<String, Object>>();

	public ArrayList<LineDataSet> dataLista1 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista2 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista3 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista4 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista5 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista6 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista7 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataLista8 = new ArrayList<LineDataSet>();

	public ArrayList<LineDataSet> dataListb1 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb2 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb3 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb4 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb5 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb6 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb7 = new ArrayList<LineDataSet>();
	public ArrayList<LineDataSet> dataListb8 = new ArrayList<LineDataSet>();

	private ArrayList<LineDataSet> dataListc1 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc2 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc3 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc4 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc5 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc6 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc7 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListc8 = new ArrayList<LineDataSet>();

	private ArrayList<LineDataSet> dataListd1 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd2 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd3 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd4 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd5 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd6 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd7 = new ArrayList<LineDataSet>();
	private ArrayList<LineDataSet> dataListd8 = new ArrayList<LineDataSet>();

	public ArrayList<ArrayList<LineDataSet>> dataListArrayList = new ArrayList<ArrayList<LineDataSet>>();

	private LineDataSet dataSet = new LineDataSet(null, "");

	public RawDataUtil(String folderName, String fileName, Context context) {
		super();
		this.folderName = folderName;
		this.fileName = fileName;
		this.context = context;
		getInfo();
		getGenenData();
		getLineDate();
	}

	private void getGenenData() {
		int index = 0;

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (i == 15) {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",,dataSourceListBlock2", index))
						.trim();

			} else {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",item_image:", nextIndex))
						.trim();
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock1.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (contextString.indexOf("item_image:", nextIndex) < 0) {

				// TODO 最后一位不出来颜色bug在这以后再改
				if ("Absolute Quantitation"
						.equals(SharedPreferencesUtils
								.get(context,
										BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
										""))
						| "绝对定量".equals(SharedPreferencesUtils
								.get(context,
										BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
										""))) {
					item_type = contextString
							.substring(
									contextString.indexOf("item_type:",
											index) + 10,
									contextString.indexOf(",,cameraSet",
											nextIndex)).trim();
				} else if ("Standard Curve Relative Quantitation"
						.equals(SharedPreferencesUtils
								.get(context,
										BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
										""))
						| "标准曲线相对定量"
								.equals(SharedPreferencesUtils
										.get(context,
												BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
												""))) {
					item_type = contextString
							.substring(
									contextString.indexOf("item_type:",
											index) + 10,
									contextString.indexOf(
											",,endogenousControl",
											nextIndex)).trim();
				} else if ("⊿Ct Relative Quantitation"
						.equals(SharedPreferencesUtils
								.get(context,
										BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
										""))
						| "比较ct值相对定量"
								.equals(SharedPreferencesUtils
										.get(context,
												BaseApplication.BASEINFORMATION_EXPERIMENTTYPE,
												""))) {
					item_type = contextString
							.substring(
									contextString.indexOf("item_type:",
											index) + 10,
									contextString.indexOf(
											",,endogenousControl",
											nextIndex)).trim();
				}
				// ByAlert.alert(contextString.substring(
				// contextString.indexOf("item_type:", index) + 10,
				// contextString.length()-1));
			} else {
				if (i == 15) {
					
				} else {
					item_type = contextString.substring(
							contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",item_image:", nextIndex))
							.trim();
				}
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock2.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		HashSet<Integer> positionsArrayList = new HashSet<Integer>();
		positionsArrayList = (HashSet<Integer>) SharedPreferencesUtils.get(
				context, "positionsArrayList", null);
		if (positionsArrayList != null) {
			for (int i : positionsArrayList) {
				if (i < 16) {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock1.set(i, hashMap);
				} else {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock2.set(i - 16, hashMap);
				}
			}
		}

	}

	private void getLineDate() {

		ArrayList<Entry> yValues = new ArrayList<Entry>();
		if(!contextString.toString().contains("Raw Data")){
		
			return;
		}
		contextString = new StringBuffer(contextString.substring(
				contextString.indexOf("Raw Data"),
				contextString.length()).toString());
		for (int n = 1; n <= 4; n++) {
			int index = 0;
			String linshi = "";// 判断通道是否有数据
			switch (n) {
			case 1:
				index = contextString.indexOf("Channel1,line1,") + 9;

				linshi = contextString.substring(contextString.indexOf("line1"
						+ ",", index - 1) + 5,

				contextString.indexOf("line2" + ",", index));

				break;
			case 2:
				index = contextString.indexOf("Channel2,line1,") + 9;
				linshi = contextString.substring(contextString.indexOf("line1"
						+ ",", index - 1) + 5,

				contextString.indexOf("line2" + ",", index));
				break;
			case 3:
				index = contextString.indexOf("Channel3,line1,") + 9;
				linshi = contextString.substring(contextString.indexOf("line1"
						+ ",", index - 1) + 5,

				contextString.indexOf("line2" + ",", index));
				break;
			case 4:
				index = contextString.indexOf("Channel4,line1,") + 9;
				linshi = contextString.substring(contextString.indexOf("line1"
						+ ",", index - 1) + 5,

				contextString.indexOf("line2" + ",", index));
				break;
			default:
				break;
			}

			for (int i = 1; i <= 32; i++) {
				yValues = new ArrayList<Entry>();
				// 截取当前线所有数据
				int nexti = i + 1;
				String lineDataStr = "";

				if (i < 32) {
					lineDataStr = contextString
							.substring(contextString.indexOf("line" + i + ",",
									index - 1) + 5,

							contextString.indexOf("line" + nexti + ",", index));
				} else {
					lineDataStr = contextString.substring(contextString
							.indexOf("line" + i + ",", index - 1) + 5);
				}

				int indexj = 0;
				for (int j = 0; j < repititions; j++) {
					Float fyValue = 0f;

					if (j < 10) {
						int firstDouhao = lineDataStr.indexOf(",", indexj) + 1;
						try {

							fyValue = Float.parseFloat(lineDataStr.substring(
									lineDataStr.indexOf(",", indexj) + 1,

									lineDataStr.indexOf(",", firstDouhao)));

						} catch (Exception e) {
							// TODO: handle exception
						}

						yValues.add(new Entry(fyValue, j));
					} else {

						int firstDouhao = lineDataStr.indexOf(",", indexj) + 1;
						try {
							fyValue = Float.parseFloat(lineDataStr.substring(
									lineDataStr.indexOf(",", indexj) + 1,

									lineDataStr.indexOf(",", firstDouhao)));

							yValues.add(new Entry(fyValue, j));
						} catch (Exception e) {
							// TODO: handle exception
						}

					}
					indexj = lineDataStr.indexOf(",", indexj) + 1;

				}
				String color = "";
				switch (i) {
				case 1:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista1.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(0).get("item_image")
										.toString(), 1);
						dataLista1.add(dataSet);

						if ("sample".equals(dataSourceListBlock1.get(0).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(0).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(0).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(0).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}

					break;
				case 2:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista2.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(1).get("item_image")
										.toString(), 1);
						dataLista2.add(dataSet);

						if ("sample".equals(dataSourceListBlock1.get(1).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(1).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(1).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(1).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 3:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista3.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(2).get("item_image")
										.toString(), 1);
						dataLista3.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(2).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(2).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(2).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(2).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 4:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista4.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(3).get("item_image")
										.toString(), 1);
						dataLista4.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(3).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(3).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(3).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(3).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 5:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista5.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(4).get("item_image")
										.toString(), 1);
						dataLista5.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(4).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(4).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(4).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(4).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 6:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista6.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(5).get("item_image")
										.toString(), 1);
						dataLista6.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(5).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(5).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(5).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(5).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 7:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista7.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(6).get("item_image")
										.toString(), 1);
						dataLista7.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(6).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(6).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(6).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(6).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 8:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataLista8.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(7).get("item_image")
										.toString(), 1);
						dataLista8.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(7).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(7).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(7).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(7).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 9:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb1.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(8).get("item_image")
										.toString(), 1);
						dataListb1.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(8).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(8).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(8).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(8).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 10:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb2.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(9).get("item_image")
										.toString(), 1);
						dataListb2.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(9).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1
								.get(9).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1
								.get(9).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1
								.get(9).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 11:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb3.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(10).get("item_image")
										.toString(), 1);
						dataListb3.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(10).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								10).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								10).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								10).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 12:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb4.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(11).get("item_image")
										.toString(), 1);
						dataListb4.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(11).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								11).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								11).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								11).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 13:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb5.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(12).get("item_image")
										.toString(), 1);
						dataListb5.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(12).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								12).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								12).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								12).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 14:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb6.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(13).get("item_image")
										.toString(), 1);
						dataListb6.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(13).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								13).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								13).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								13).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 15:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb7.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(14).get("item_image")
										.toString(), 1);
						dataListb7.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(14).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								14).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								14).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								14).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 16:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListb8.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock1.get(15).get("item_image")
										.toString(), 1);
						dataListb8.add(dataSet);
						if ("sample".equals(dataSourceListBlock1.get(15).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock1.get(
								15).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock1.get(
								15).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock1.get(
								15).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 17:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc1.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(0).get("item_image")
										.toString(), 1);
						dataListc1.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(0).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(0).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(0).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(0).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 18:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc2.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(1).get("item_image")
										.toString(), 1);
						dataListc2.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(1).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(1).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(1).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(1).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 19:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc3.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(2).get("item_image")
										.toString(), 1);
						dataListc3.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(2).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(2).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(2).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(2).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 20:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc4.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(3).get("item_image")
										.toString(), 1);
						dataListc4.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(3).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(3).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(3).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(3).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 21:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc5.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(4).get("item_image")
										.toString(), 1);
						dataListc5.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(4).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(4).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(4).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(4).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 22:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc6.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(5).get("item_image")
										.toString(), 1);
						dataListc6.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(5).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(5).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(5).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(5).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 23:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc7.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(6).get("item_image")
										.toString(), 1);
						dataListc7.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(6).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(6).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(6).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(6).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 24:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListc8.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(7).get("item_image")
										.toString(), 1);
						dataListc8.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(7).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(7).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(7).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(7).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 25:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd1.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(8).get("item_image")
										.toString(), 1);
						dataListd1.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(8).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(8).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(8).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(8).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 26:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd2.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(9).get("item_image")
										.toString(), 1);
						dataListd2.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(9).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2
								.get(9).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2
								.get(9).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2
								.get(9).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}

					break;
				case 27:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd3.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(10).get("item_image")
										.toString(), 1);
						dataListd3.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(10).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								10).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								10).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								10).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 28:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd4.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(11).get("item_image")
										.toString(), 1);
						dataListd4.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(11).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								11).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								11).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								11).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 29:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd5.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(12).get("item_image")
										.toString(), 1);
						dataListd5.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(12).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								12).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								12).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								12).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;

				case 30:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd6.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(13).get("item_image")
										.toString(), 1);
						dataListd6.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(13).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								13).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								13).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								13).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 31:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd7.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(14).get("item_image")
										.toString(), 1);
						dataListd7.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(14).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								14).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								14).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								14).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;
				case 32:
					if (linshi.length() < 2) {
						LineDataSet lineDataSet = new LineDataSet(
								new ArrayList<Entry>(), "");
						dataListd8.add(lineDataSet);
					} else {
						addLineChart(yValues,
								dataSourceListBlock2.get(15).get("item_image")
										.toString(), 1);
						dataListd8.add(dataSet);
						if ("sample".equals(dataSourceListBlock2.get(15).get(
								"item_type"))) {
							color = "#ff2d55";
						} else if ("standard".equals(dataSourceListBlock2.get(
								15).get("item_type"))) {
							color = "#fd9727";
						} else if ("positive".equals(dataSourceListBlock2.get(
								15).get("item_type"))) {
							color = "#ff00a9";
						} else if ("negative".equals(dataSourceListBlock2.get(
								15).get("item_type"))) {
							color = "#159588";

						} else {
							color = "#ffffff";
						}
						addLineChart(yValues, color, 2);
					}
					break;

				default:
					break;
				}
				index = contextString.indexOf("line" + nexti + ",", index);

			}

		}

		// 构建一个LineDataSet 代表一组Y轴数据 （比如不同的彩票: 七星彩 双色球）

		// dataSeta8 = new LineDataSet(yValue7, "");
		// dataSeta8.setColor(Color.RED);// 设置颜色
		// dataSeta8.setLineWidth(1);
		// dataSeta8.setCircleSize(0f);
		// dataSeta8.setValueTextSize(0);

		// 把数据都放到总集合中dataListArrayList
		dataListArrayList.add(dataLista1);
		dataListArrayList.add(dataLista2);
		dataListArrayList.add(dataLista3);
		dataListArrayList.add(dataLista4);
		dataListArrayList.add(dataLista5);
		dataListArrayList.add(dataLista6);
		dataListArrayList.add(dataLista7);
		dataListArrayList.add(dataLista8);
		dataListArrayList.add(dataListb1);
		dataListArrayList.add(dataListb2);
		dataListArrayList.add(dataListb3);
		dataListArrayList.add(dataListb4);
		dataListArrayList.add(dataListb5);
		dataListArrayList.add(dataListb6);
		dataListArrayList.add(dataListb7);
		dataListArrayList.add(dataListb8);
		dataListArrayList.add(dataListc1);
		dataListArrayList.add(dataListc2);
		dataListArrayList.add(dataListc3);
		dataListArrayList.add(dataListc4);
		dataListArrayList.add(dataListc5);
		dataListArrayList.add(dataListc6);
		dataListArrayList.add(dataListc7);
		dataListArrayList.add(dataListc8);
		dataListArrayList.add(dataListd1);
		dataListArrayList.add(dataListd2);
		dataListArrayList.add(dataListd3);
		dataListArrayList.add(dataListd4);
		dataListArrayList.add(dataListd5);
		dataListArrayList.add(dataListd6);
		dataListArrayList.add(dataListd7);
		dataListArrayList.add(dataListd8);

	}

	private void getInfo() {

		//
		folderName = SharedPreferencesUtils.get(context,
				BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(context,
				BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		
		FileInputStream in =null;
		BufferedReader reader=null;
		contextString=new StringBuffer();
		try {
			in =new FileInputStream(file);
			reader=new BufferedReader(new InputStreamReader(in));
			String line ="";
			while((line =reader.readLine())!=null){
				contextString.append(line);
				contextString.append(",");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(reader != null){
				try {
					reader.close();
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
		
//		BufferedReader reader = null;
//		contextString=new StringBuffer();
//		System.gc();
//		try {
//			System.out.println("以行为单位读取文件内容，一次读一整行:");
//			reader = new BufferedReader(new FileReader(file));
//			String tempString = null;
//			int line = 1;
//			// 一次读入一行，直到读入null为文件结束
//			while ((tempString = reader.readLine()) != null) {
//				// 显示行号
//				// System.out.println("line " + line + ": " + tempString);
//				// Log.e("--", tempString);
//				contextString.append(tempString);
//				contextString.append(",");
//				line++;
//			}
//			reader.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (reader != null) {
//				try {
//					reader.close();
//					// LogUtil.e("!!", contextString + "");
//
//				} catch (IOException e1) {
//				}
//			}
//		}

		int index = 0;
		// 上面解析
		while (!(contextString.indexOf("steptType:", index) <= 0)) {

			// steptType:
			String steptType;
			steptType = contextString.substring(
					contextString.indexOf("steptType:", index) + 10,

					contextString.indexOf(",temperature:", index));

			// LogUtil.e(steptType);

			// temperature
			String temperature;
			temperature = contextString.substring(
					contextString.indexOf(",temperature:", index) + 13,

					contextString.indexOf(",time:", index));

			// LogUtil.e(temperature);
			// time
			String time;
			time = contextString.substring(
					contextString.indexOf(",time:", index) + 6,

					contextString.indexOf(",goTo:", index));
			// LogUtil.e(time);

			// goTo
			String goTo;
			goTo = contextString.substring(
					contextString.indexOf(",goTo:", index) + 6,

					contextString.indexOf(",Repititions:", index));
			// LogUtil.e(goTo);
			// Repititions
			String repititions;
			repititions = contextString.substring(
					contextString.indexOf(",Repititions:", index) + 13,

					contextString.indexOf(",deltaT:", index));
			// LogUtil.e(repititions);
			// deltaT
			String deltaT;
			deltaT = contextString.substring(
					contextString.indexOf(",deltaT:", index) + 8,

					contextString.indexOf(",rightSelect:", index));
			// LogUtil.e(deltaT);

			int nextIndex = contextString.indexOf("steptType:", index) + 10;

			// rightSelect
			String rightSelect;

			if (contextString.indexOf(",steptType:", nextIndex) < 0) {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,
						contextString.indexOf(",,pointMap", index));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}

			} else {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,

						contextString.indexOf(",steptType:", nextIndex));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}
			}
			// LogUtil.e(rightSelect);
			index = contextString.indexOf(",rightSelect:", index) + 13;

			activityMethodBeans.add(new MethodBean(steptType.trim(),
					temperature.trim(), time.trim(), goTo.trim(), repititions
							.trim(), deltaT.trim()));
		}
		// 获取重复次数

		int stepNum = Integer.parseInt(contextString.substring(
				contextString.indexOf(",readDataString: ") + 17,
				contextString.indexOf(",,Methods")).trim());
		repititionsGet(stepNum);

		// layoutOne的数据解析
		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		// LogUtil.e(contextString.indexOf(",Aisle") + 7);
		// LogUtil.e(contextString.indexOf(",Color"));

		index = 0;
		while (!(contextString.indexOf("Aisle", index) <= 0)) {

			// Aisle:
			String aisle;
			aisle = contextString.substring(
					contextString.indexOf(",Aisle", index) + 7,

					contextString.indexOf(",Color", index));
			// LogUtil.e(aisle);

			// Color
			String color;
			color = contextString.substring(
					contextString.indexOf(",Color", index) + 7,

					contextString.indexOf(",Target", index));
			// LogUtil.e(color);

			// Target
			String target;
			target = contextString.substring(
					contextString.indexOf(",Target", index) + 8,

					contextString.indexOf(",Dyes", index));

			// LogUtil.e(target);

			int nextIndex = contextString.indexOf(",Aisle", index) + 7;

			// Dyes
			String dyes;
			if (contextString.indexOf(",Aisle", nextIndex) < 0) {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,
						contextString.indexOf(",,dataSourceListBlock1", index));

				// LogUtil.e(dyes);
			} else {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,

						contextString.indexOf(",Aisle", nextIndex));
				// LogUtil.e(dyes);
			}

			index = contextString.indexOf(",Dyes", index) + 5;

			activityLayoutTableBeans.add(new LayoutTableBean(false, Integer
					.parseInt(aisle.trim()), Integer.parseInt(color.trim()),
					target, dyes));

		}

	}

	private void repititionsGet(int stepNum) {
		// 先找出拍照的位置
		int cameraStep = stepNum-1;
//		for (MethodBean bean : activityMethodBeans) {
//			if (bean.getRightSelect()) {
//				break;
//			}
//			cameraStep++;
//		}
		ArrayList<ArrayList<Integer>> ranges = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> littleRange;
		int startStep = 0;
		for (MethodBean bean : activityMethodBeans) {
			if (!TextUtils.isEmpty(bean.getGoTo())) {
				littleRange = new ArrayList<Integer>();
				littleRange.add(startStep);
				littleRange.add(Integer.parseInt(bean.getGoTo())-1);
				ranges.add(littleRange);
			}
			startStep++;
		}

		// 判断有没有跳转
		if (ranges.size() == 0) {
			repititions = 1;
			return;
		} else {
			int sum = 1;
			for (ArrayList<Integer> little : ranges) {
				if (cameraStep <= little.get(0)) {
					if (cameraStep >= little.get(1)) {
						sum = sum * Integer.parseInt(activityMethodBeans.get(little.get(0)).getRepititions());
					}
				}
			}
			repititions = sum;
			return;
		}

	}

	private void addLineChart(ArrayList<Entry> yValues, String colorString,
			int type) {
		dataSet = new LineDataSet(yValues, "");
		// dataSet.setLineWidth(0);
		if (type == 1) {
			if (TextUtils.isEmpty(colorString)) {
				dataSet.setColor(color.white);
			} else {
				dataSet.setColor(context.getResources().getColor(
						getcolor(colorString)));
			}
		} else if (type == 2) {
			if (TextUtils.isEmpty(colorString)) {
				dataSet.setColor(color.white);
			} else {
				dataSet.setColor(Color.parseColor(colorString));
			}
		}

		dataSet.setCircleSize(0);
		dataSet.setValueTextSize(0);
		dataSet.setLineWidth(1);
	}

	private int getcolor(String colorString) {
		switch (Integer.parseInt(colorString)) {
		case 11:
			return R.color.palette_one_one;

		case 12:

			return R.color.palette_one_two;
		case 13:

			return R.color.palette_one_three;
		case 14:

			return R.color.palette_one_four;
		case 15:

			return R.color.palette_one_five;
		case 16:

			return R.color.palette_one_six;
		case 21:

			return R.color.palette_two_one;
		case 22:

			return R.color.palette_two_two;
		case 23:

			return R.color.palette_two_three;
		case 24:

			return R.color.palette_two_four;
		case 25:

			return R.color.palette_two_five;
		case 26:

			return R.color.palette_two_six;
		case 31:
			return R.color.palette_three_one;
		case 32:

			return R.color.palette_three_two;
		case 33:

			return R.color.palette_three_three;
		case 34:

			return R.color.palette_three_four;
		case 35:

			return R.color.palette_three_five;
		case 36:

			return R.color.palette_three_six;
		case 41:
			return R.color.palette_four_one;

		case 42:

			return R.color.palette_four_two;
		case 43:

			return R.color.palette_four_three;
		case 44:

			return R.color.palette_four_four;
		case 45:

			return R.color.palette_four_five;
		case 46:

			return R.color.palette_four_six;
		case 51:

			return R.color.palette_five_one;
		case 52:

			return R.color.palette_five_two;
		case 53:

			return R.color.palette_five_three;
		case 54:

			return R.color.palette_five_four;
		case 55:

			return R.color.palette_five_five;
		case 56:

			return R.color.palette_five_six;
		case 61:

			return R.color.palette_six_one;
		case 62:

			return R.color.palette_six_two;
		case 63:

			return R.color.palette_six_three;
		case 64:

			return R.color.palette_six_four;
		case 65:

			return R.color.palette_six_five;
		case 66:

			return R.color.palette_six_six;

		default:
			return 0;
		}

	}

	public StringBuffer getContextString() {
		return contextString;
	}

	public void setContextString(StringBuffer contextString) {
		this.contextString = contextString;
	}

	public ArrayList<MethodBean> getActivityMethodBeans() {
		return activityMethodBeans;
	}

	public void setActivityMethodBeans(ArrayList<MethodBean> activityMethodBeans) {
		this.activityMethodBeans = activityMethodBeans;
	}

	public int getRepititions() {
		return repititions;
	}

	public void setRepititions(int repititions) {
		this.repititions = repititions;
	}

	public ArrayList<LayoutTableBean> getActivityLayoutTableBeans() {
		return activityLayoutTableBeans;
	}

	public void setActivityLayoutTableBeans(
			ArrayList<LayoutTableBean> activityLayoutTableBeans) {
		this.activityLayoutTableBeans = activityLayoutTableBeans;
	}

	public List<HashMap<String, Object>> getDataSourceListBlock1() {
		return dataSourceListBlock1;
	}

	public void setDataSourceListBlock1(
			List<HashMap<String, Object>> dataSourceListBlock1) {
		this.dataSourceListBlock1 = dataSourceListBlock1;
	}

	public List<HashMap<String, Object>> getDataSourceListBlock2() {
		return dataSourceListBlock2;
	}

	public void setDataSourceListBlock2(
			List<HashMap<String, Object>> dataSourceListBlock2) {
		this.dataSourceListBlock2 = dataSourceListBlock2;
	}

	public ArrayList<ArrayList<LineDataSet>> getDataListArrayList() {
		return dataListArrayList;
	}

	public void setDataListArrayList(
			ArrayList<ArrayList<LineDataSet>> dataListArrayList) {
		this.dataListArrayList = dataListArrayList;
	}

}
